      PROGRAM NewtRaphsEquSyst
 ! Solving a system of equation, using Newton-Raphson method.

      ! Variables
      implicit none
      real*8 x,y,f,g,dfx,dgx,dfy,dgy,x_numerator,y_numerator
      real*8 denominator,xnext,ynext,eps
      integer count
      count=0
      
      ! Welcome interface
      write(*,*)'Solving a system of non-linear equations, using Newton-Raphson method'
      write(*,*)'Enter initial x, y roots and error value:'
      read(*,*)x,y,eps
      write(*,*)'Initial x=',x,'Initial y=',y
      write(*,*)'                 Accuracy=',eps
      write(*,*)
      
      ! Main program
 77   x_numerator=f(x,y)*dgy(x)-g(x,y)*dfy(y)
      y_numerator=g(x,y)*dfx(x)-f(x,y)*dgx(x,y)
      denominator=dfx(x)*dgy(x)-dgx(x,y)*dfy(y)
      xnext=x-(x_numerator)/denominator
      ynext=y-(y_numerator)/denominator
      x=xnext
      y=ynext
      count=count+1
      write(*,*)'Iteration=',count
      write(*,*)'x-root=',x,'y-root=',y
      write(*,*)'----------------------------------------------------------------'
      if((f(x,y).lt.eps).AND.(g(x,y).lt.eps)) then
        goto 99
      endif
      goto 77
      
 99   continue
      end

 ! These are my functions.
      real*8 function f(x,y)
      real*8 x,y
      f=2.*exp(x)-y
      return
      END

      real*8 function g(x,y)
      real*8 x,y
      g=x*y-exp(x)
      return
      END

 ! These are the p-derivatives.
      real*8 function dfx(x)
      real*8 x
      dfx=2.*exp(x)
      return
      END

      real*8 function dfy(y)
      real*8 y
      dfy=-1.
      return
      END

      real*8 function dgx(x,y)
      real*8 x,y
      dgx=y-exp(x)
      return
      END

      real*8 function dgy(x)
      real*8 x
      dgy=x
      return
      END